<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="定标单号" prop="calibrationCode">
        <el-input
          v-model="queryParams.calibrationCode"
          placeholder="请输入定标单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="询价单号" prop="enquiryCode">
        <el-input
          v-model="queryParams.enquiryCode"
          placeholder="请输入询价单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="定标时间" prop="params">
        <el-date-picker
          clearable
          v-model="queryParams.params"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd"
          placeholder="请选择定标时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="定标人" prop="calibrationUser">
        <el-input
          v-model="queryParams.calibrationUser"
          placeholder="请输入定标人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table border v-loading="loading" :data="calibrationList">
      <el-table-column label="定标单编号" align="center" prop="calibrationCode">
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="handleView(scope.row)"
          >{{ scope.row.calibrationCode }}
          </el-button>
        </template>
      </el-table-column>
      <el-table-column label="询价单编号" align="center" prop="enquiryCode">
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="handleEnquiryView(scope.row)"
          >{{ scope.row.enquiryCode }}
          </el-button>
        </template>
      </el-table-column>
      <el-table-column label="定标时间" align="center" prop="calibrationTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.calibrationTime, '{y}-{m}-{d} {h}:{i}:{s}')}}</span>
        </template>
      </el-table-column>
      <el-table-column label="定标人" align="center" prop="calibrationUser"/>
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <span v-if="scope.row.status === '0'">草稿</span>
          <span v-if="scope.row.status === '1'">询价中</span>
          <span v-if="scope.row.status === '2'">定标中</span>
          <span v-if="scope.row.status === '3'">待审批</span>
          <span v-if="scope.row.status === '4'">已审批</span>
        </template>
      </el-table-column>
      <el-table-column label="含税金额" align="center" prop="taxAmount"/>
      <el-table-column label="不含税金额" align="center" prop="noTaxAmount"/>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <EnquiryInfoView ref="enquiryInfoView"></EnquiryInfoView>
    <CalibrationInfoView ref="calibrationInfoView"></CalibrationInfoView>

  </div>
</template>

<script>
import {listCalibration} from "@/api/mes/cg/calibration";
import EnquiryInfoView from "@/views/mes/cg/enquiry/infoView.vue";
import CalibrationInfoView from "@/views/mes/cg/calibration/infoView.vue";

export default {
  name: "Calibration",
  components: {EnquiryInfoView,CalibrationInfoView},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 采购管理-定标单表格数据
      calibrationList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        calibrationCode: null,
        enquiryCode: null,
        calibrationTime: null,
        calibrationUser: null,
        params:[]
      },

    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询采购管理-定标单列表 */
    getList() {
      this.loading = true;
      const query = {...this.queryParams};
      if (query.params && query.params.length === 2) {
        query.params = {
          beginTime: query.params[0],
          endTime: query.params[1]
        };
      } else {
        query.params = null;
      }
      listCalibration(query).then(response => {
        this.calibrationList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleView(row){
      this.$refs.calibrationInfoView.init(row.id)
    },
    handleEnquiryView(row){
      this.$refs.enquiryInfoView.init(row.enquiryId);
    }

  }
};
</script>
